package netty.serializable.objectdecoderandencoder.server;

import netty.serializable.objectdecoderandencoder.client.OrderReq;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;


public class OrderServerHandler extends ChannelHandlerAdapter{

	private static int count = 0;
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		ctx.close();
	}

	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		OrderReq req = (OrderReq) msg;
		if("likaiqiang".equals(req.getOrderAuthor())){
			System.out.println("receive order request:" + ++count + " " + req.toString());
		}
		ctx.writeAndFlush(OrderObjectConvert.toResp(req));
		
	}
	
	
	
}
